package com.mtjx.exception;

import com.mtjx.resp.VfResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 33117
 * @version 1.0
 * @data 2025/8/19 16:42
 */
@ControllerAdvice
@Slf4j
public class VisionFloeException {
    /**
     * 处理不可控异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public VfResult exception(Exception e) {
        e.printStackTrace();
        log.error("catch exception:{}", e.getMessage());
        return VfResult.errorMsg(e.getMessage());
    }

    /**
     * 处理可控异常  自定义异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public VfResult exception(CustomException e) {
        log.error("catch exception:{}", e);
        return VfResult.errorMsg(e.getCode(), e.getMessage());
    }
}
